package com.od.mapper;

import com.od.entity.Category;
import com.od.utils.IndustryCategory;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface IndustryCategoryMapper {
    @Select("SELECT * FROM industry")
    @Results({
            @Result(property = "industryId", column = "industry_id"),
            @Result(property = "industryName", column = "industry_name"),
            @Result(property = "categories", column = "industry_id", many = @Many(select = "selectCategoriesByIndustryId"))
    })
    List<IndustryCategory> selectAllIndustries();

    @Select("SELECT * FROM category WHERE category_industry = #{industryId}")
    @Results({
            @Result(property = "categoryId", column = "category_id"),
            @Result(property = "categoryName", column = "category_name"),
            @Result(property = "categoryIndustry", column = "category_industry")
    })
    List<Category> selectCategoriesByIndustryId(int industryId);
}
